package com.hong.chapter6;

public class ThreadInterrupt {

    private static Object MONITOR = new Object();

    public static void main(String[] args) throws InterruptedException {



       /* Thread  t1 = new Thread(){
            @Override
            public void run() {
                while (true){
                   *//* try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        System.out.println("收到打断信号");
                        e.printStackTrace();
                    }*//*
                   synchronized (MONITOR){
                       try {
                           MONITOR.wait(10);
                       } catch (InterruptedException e) {
                           e.printStackTrace();
                       }
                   }

                }
            }
        };
        t1.start();
        Thread.sleep(1000);
        System.out.println(t1.isInterrupted());
        t1.interrupt();
        System.out.println(t1.isInterrupted());
        t1.stop();*/


        Thread t = new Thread(){
            @Override
            public void run() {
                while (true){

                }
            }
        };
        t.start();
        Thread main = Thread.currentThread();
        Thread t2 = new Thread(){
            @Override
            public void run() {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                main.interrupt();
                System.out.println("interrout");
            }
        };

        t2.start();
        try{
            t.join();
        }catch (Exception e){
            e.printStackTrace();
        }

    }


}
